package com.qc.qx.controller;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.qc.qx.services.ThumbnailService;
import com.qc.qx.services.UploadService;

@Controller
@RequestMapping("/uploadFile/")
public class ThumbnailController {
	@Autowired
	private UploadService uploadService;
	@Autowired
	private ThumbnailService thumbnailService;

	@RequestMapping("upload")
	public String thumbnail(@RequestParam("fileNamePath") CommonsMultipartFile file, HttpSession session, Map<String, Object> map) {

		// 图片保存的的文件名称
		String uploadPath = "images";
		// 项目发布的路径
		String realUploadPath = session.getServletContext().getRealPath(uploadPath);

		String imgeUrl = "";
		String thumbnailImageUrl = "";

		// 上传图片
		imgeUrl = uploadService.uploadImage(file, uploadPath, realUploadPath);
		// 压缩图片
		thumbnailImageUrl = thumbnailService.thumbnail(file, uploadPath, realUploadPath);

		map.put("imgeUrl", imgeUrl);
		map.put("thumbnailImageUrl", thumbnailImageUrl);
		return "showImage";
	}

}
